<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
/**
 * Description of ClwzController
 *
 * @author Xie
 */
class ClwzController  extends ApiController{
    public function getLog(){
        $url = "http://xmitcc.xmjj.gov.cn/jtwf/vio/jdc/jdcwfcx";
        $post_data = Input::get('data');
        $cookie_file = resource_path('tmp')."/cookie.txt";
        $str_data = http_build_query($post_data);

        $ch=curl_init (); 
        curl_setopt ($ch,CURLOPT_URL,$url ); 
        curl_setopt ($ch,CURLOPT_HEADER,0 ); 
        curl_setopt ($ch,CURLOPT_TIMEOUT,5 ); 
        curl_setopt ($ch,CURLOPT_POST,true ); 
        curl_setopt ($ch,CURLOPT_POSTFIELDS,$str_data ); 
        //curl_setopt ($ch,CURLOPT_HTTPHEADER,$header ); 
        curl_setopt ($ch,CURLOPT_COOKIEFILE,$cookie_file ); 
        $header = [
                'Referer'=>'http://xmitcc.xmjj.gov.cn/jtwf/vio/jdc?'.$str_data,
                'User-Agent'=>'User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36'
        ];
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        //curl_setopt ($ch,CURLOPT_PROXY,"202.194.101.150:80"); 
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER,1 ); 
        $output = curl_exec ($ch ); 
        curl_close ($ch ); 
        //打印获得的数据
        include_once(resource_path('inc')."/simple_html_dom.php");
        $dom = str_get_html($output);
        if($dom){
            $div = $dom->find('div[class=endlist8]',0);
            if($div){
                $result = $div->plaintext;
                return view('clwzcxjg',['result'=>$result]);
            }
        }
        return view('clwzcxjg',['result'=>$output]);
    }

    public function verifycode(){
        $cookie_file = './cookie.txt';
//这是验证码地址
        $verify_code_url = "http://xmitcc.xmjj.gov.cn/jtwf/ClinicCountManager/captcha-image.do";
        $curl = curl_init ();
        curl_setopt ($curl,CURLOPT_URL,$verify_code_url );
        curl_setopt ($curl,CURLOPT_COOKIEJAR,$cookie_file );
        curl_setopt ($curl, CURLOPT_HEADER,false );
        $header = [
            'Referer'=>'http://www.xmjj.gov.cn/xxfw/shouye.action',
            'User-Agent'=>'User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36'
        ];
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt ($curl,CURLOPT_RETURNTRANSFER,true );
        $img = curl_exec ($curl );
        curl_close ($curl );
        //保存验证码
        echo $img;
    }
}
